import React, { PureComponent } from 'react'
import { CSSTransition } from 'react-transition-group'

import { Card, Avatar, Button } from 'antd';
import { EditOutlined, EllipsisOutlined, SettingOutlined } from '@ant-design/icons';

import './CSSTransition.css'

const { Meta } = Card;

export default class CSSTransitionDemo extends PureComponent {
  constructor(props) {
    super(props);

    this.state = {
      isShow: true
    }
  }

  render() {
    const { isShow } = this.state
    return (
      <div>
        <Button onClick={e => this.setState({ isShow: !isShow })
        } type="primary">显示/隐藏</Button>
        <CSSTransition
          // 设置类名
          classNames="card"
          in={this.state.isShow}
          timeout={300}
          // 设置隐藏后从DOM中卸载
          unmountOnExit={true}
          // 增加页面加载动画
          appear

          // 生命周期
          onEnter={el => { console.log("进入状态"); }}
          onEntering={el => { console.log("正在进入"); }}
          onEntered={el => { console.log("进入完成"); }}

          onExit={el => { console.log("开始退出"); }}
          onExiting={el => { console.log("退出状态"); }}
          onExited={el => { console.log("退出完成"); }}
          >
          <Card
            style={{ width: 300 }}
            cover={
              <img
                alt="example"
                src="https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png"
              />
            }
            actions={[
              <SettingOutlined key="setting" />,
              <EditOutlined key="edit" />,
              <EllipsisOutlined key="ellipsis" />,
            ]}
          >
            <Meta
              avatar={<Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />}
              title="Card title"
              description="This is the description"
            />
          </Card>
        </CSSTransition>
      </div>
    )
  }
}
